package UserThread;
import android.app.Activity;

import java.io.IOException;

import UserClientSocket.Client;
import UserGlobal.GlobalData;
//好友列表更新线程
public class FriendSwipeThread extends Thread {
    Runnable mAction;
    Activity mActivity;
    public FriendSwipeThread(Runnable action, Activity activity){
        mAction=action;
        mActivity=activity;
    }
    @Override
    public void run() {
        GlobalData.idlist.clear();//清空防止过往数据存在
        try {
            Client mClient = new Client(3000,0,0);

            mClient.sendString("requestsidlist");
            while (!isInterrupted()) {
                String str = mClient.receiveString();//在线的好友id
                if (str.equals("-1")) {
                    mActivity.runOnUiThread(mAction);
                    for(int i=0;i<GlobalData.mHistoryId.size();i++){
                        if(GlobalData.idlist.indexOf(GlobalData.mHistoryId.get(i))==-1){
//                            if(GlobalData.Friendid.equals(GlobalData.mHistoryId.get(i))){
//                                GlobalData.Friendid="";
//                            }
                            GlobalData.mHistoryId.remove(i);
                            GlobalData.mChatHistory.remove(i);
                            //GlobalData.mGravityList.clear();
                        }
                    }
                    break;
                } else {
                    if(GlobalData.idlist.indexOf(str)==-1&&!str.equals(GlobalData.Myid)){//排查重复id和用户id
                        GlobalData.idlist.add(str);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
